<template>
	<div>
		<div v-if="original">
		<div class="graybg"></div>
		<!--头部-->
		<header id="header">
			<div class="header header_bg clearfix">
				<div class="header_left pull-left">
					<i class="iconfont baiColor" onclick="javascript:history.back(-1)">&#xe612;</i>
				</div>
				<div class="header_center baiColor">冻积分转账</div>
				<div class="header_right">
					<router-link to="/alldetail/2">
					<em class="baiColor">转账记录</em>
					</router-link>
				</div>
			</div>
		</header>
		<div class="main _width">
			<div class="gathering marginAuto">
				<div class="gathering-each _width">
					<span>收款账号:</span>
					<input type="text" value="" placeholder="输入对方 ID" maxlength="20" v-model="gathering"/>
				</div>
				<div class="gathering-each _width">
					<span>转账金额:</span>
					<input type="number" value="" @change="gatheringMoney" placeholder="转账金额不少于100.00" v-model="gatheringmoney"/>
				</div>
			</div>
			<div class="balance _width">
				<span>您的账号余额是<i v-text="balance"></i>,最多可转<i v-text="out"></i></span>
			</div>
			<div class="gathering marginAuto">
				<div class="gathering-each _width">
					<span>您需要支付:</span>
					<span v-text="pay"></span>
				</div>
				<div class="gathering-each _width">
					<span>实际到账:</span>
					<span v-text="account"></span>
				</div>
			</div>
			<div class="balance _width">
				<span>转账手续费<i>{{charge}}%</i></span>
			</div>
		</div>
		<div class="footer-button button baiColor" @click="footerbutton">
			<span>向对方转账</span>
		</div>
		</div>
		<!--冻积分转账传给组件-->
		<newpaypass v-if="original == true ? false:true" :integral = "integral"></newpaypass>
	</div>
</template>

<script>
	import newpaypass from './wfreezepass.vue';	//活积分转活积分传给组件
	
	export default{
		components:{newpaypass},
		data(){
			return{
				original:true,//控制显示隐藏
				gathering:"",//收款账号
				gatheringmoney:"",//转账金额
				balance:"0.00",//余额
				out:"0.00",	//转出
				pay:"0.00",	//需要支付的钱数
				account:"0.00",//实际到账的钱数
				charge:"0.00", //手续费
				rate:"",	//费率
				integral:{}
			}
		},
		mounted(){
			let _this = this;
			var info = window.localStorage.data;
			var params = new URLSearchParams();
			params.append('token', info);	//客户秘钥（信息）
			this.$axios({
			   url:"Home/Money/egral_dh",
				method:"post",
				data:params
			  }).then(function(res){
			   	var datas = res.data.data;
			   	var egral_dong = datas.user_egral_dong;
			   	_this.balance = egral_dong;
				_this.out = parseFloat(egral_dong*1-egral_dong*_this.rate).toFixed(2);
			   	for(var i in datas){
		   			if(datas[i].c_key == "dong_egral"){	//活积分兑换比例[冻积分(计算费率)]
			   			_this.rate = datas[i].c_val;
			   		}
			   	}
			}).catch(function(err){
				console.log(err)		
			})
		},
		methods:{
			//获取页面中相关的数据
			gatheringMoney(){
				var _this = this;
				var gathering =  this.gathering;
				var gatheringmoney = this.gatheringmoney;	//转账金额
				if(gatheringmoney <= 99){
					alert("转账金额不少于100元")
				}else{
					_this.pay = gatheringmoney;
					_this.account = parseFloat(gatheringmoney*1-gatheringmoney*_this.rate/100).toFixed(2);
					_this.charge = parseFloat(gatheringmoney*_this.rate/100).toFixed(2);
				}
			},
			//点击想对方转账
			footerbutton(){
				let _this = this;
				var gatheringmoney = this.gatheringmoney;	//金额
				var gathering = this.gathering;		//账号
				if(gatheringmoney == "" || gathering == ""){
					alert("请将信息填写完整");
				}else{
					_this.integral  = {
						price:gatheringmoney,
						s_user_id:gathering,
						transferType:"dz"
					}
					_this.original = false;
//					var params = new URLSearchParams();
//					params.append('token', info);	//客户秘钥（信息）
//					params.append('price',gatheringmoney);
//					params.append('s_user_id',gathering);
//					this.$axios({
//					   url:"Home/Money/dong_egral_transaction",
//						method:"post",
//						data:params
//					 }).then(function(res){
//					 	if(res.data == 0){
//					 		alert("转账失败");
//					 	}else if(res.data == 1){
//					 		alert("转账成功");
//					 		_this.$router.push("wShares");
//					 	}else if(res.data == 3){
//					 		alert("积分不足")
//					 	}else if(res.data == 4){
//					 		alert("收款用户存在")
//					 	}
//					}).catch(function(err){
//						console.log(err)		
//					})
				}
			}
			
		}
	}
</script>

<style scope>
	@import "../css/public.css";
	/*@import "../css/wfreeze.css";*/
	.main{
		padding-top: 50px;
	}
	
	/*==*/
	.header_right em{
		font-size: 14px;
	}
	.gathering{
		width: 90%;
		background: #fff;
	}
	.gathering-each{
		height: 40px;
		border-bottom: 1px solid #e0dada;
	}
	.gathering-each span{
		line-height: 38px;
		margin-left: 10px;
		color: #333333;
		font-size: 16px;
	}
	.gathering-each input{
		width: 50%;
		height: 38px;
		font-size: 14px;
		line-height: 38px;
	}
	.balance{
		text-align: center;
		line-height: 30px;
		font-size: 14px;
		color:#666666;
	}
	.balance i{
		color:#F3961F;
	}
	.footer-button{
		line-height: 30px;
		background:#F3961F;
		margin-top: 50px;
	}
	
</style>